% TEST_ID: LANG-EXPAND-0058
% CATEGORY: language/function_call
% 测试嵌套函数

function test_nested()
    x_at_entry = 7;
    function inner_func4()
        x_at_inner_func4 = 1;
        assert(x_at_entry == 7);            % 读1层自由变量
        function inner_func5()
            assert(x_at_inner_func4 == 1);  % 读1层自由变量
            x_at_inner_func4 = 3;           % 写1层自由变量
            assert(x_at_inner_func4 == 3);
            assert(x_at_entry == 7);        % 读2层自由变量
            x_at_entry = 8;                 % 写2层自由变量
        end
        inner_func5()
        assert(x_at_inner_func4 == 3)        % x_at_inner_func4成功被inner_func5写入
        assert(x_at_entry == 8)             % x_at_entry成功被inner_func5写入
    end
    inner_func4()
end

